using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using JGSY.CMS.LowCode.Platform.Domain.Interfaces;

namespace JGSY.CMS.LowCode.Platform.Domain.Entities
{
    /// <summary>
    /// 团队成员实体，对应 team_members 表，复合主键 TeamId + UserId，支持多租户隔离
    /// </summary>
    [Table("team_members")]
    public class TeamMember : ITenantEntity
    {
        /// <summary>
        /// 团队ID
        /// </summary>
        [Required]
        public long TeamId { get; set; }

        /// <summary>
        /// 用户ID
        /// </summary>
        [Required]
        public long UserId { get; set; }

        /// <summary>
        /// 租户ID
        /// 用于多租户数据隔离
        /// </summary>
        [Required]
        [StringLength(50)]
        public string TenantId { get; set; } = string.Empty;
        
        /// <summary>
        /// 角色/职位
        /// 在团队中的角色，如：成员、组长、副组长等
        /// </summary>
        [StringLength(50)]
        public string? Role { get; set; }
        
        /// <summary>
        /// 加入时间
        /// </summary>
        public DateTime JoinedAt { get; set; } = DateTime.UtcNow;
        
        /// <summary>
        /// 离开时间
        /// </summary>
        public DateTime? LeftAt { get; set; }
        
        /// <summary>
        /// 成员状态
        /// 0=已离开, 1=活跃, 2=暂停
        /// </summary>
        public byte Status { get; set; } = 1;
        
        /// <summary>
        /// 权限级别
        /// 在团队中的权限级别
        /// </summary>
        public int PermissionLevel { get; set; } = 1;
        
        /// <summary>
        /// 是否团队管理员
        /// </summary>
        public bool IsAdmin { get; set; } = false;
        
        /// <summary>
        /// 备注信息
        /// </summary>
        [Column(TypeName = "text")]
        public string? Remark { get; set; }
        
        /// <summary>
        /// 添加人ID
        /// </summary>
        public long? AddedBy { get; set; }
        
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreatedAt { get; set; } = DateTime.UtcNow;

        // 导航属性
        /// <summary>
        /// 团队导航属性
        /// </summary>
        [ForeignKey(nameof(TeamId))]
        public Team? Team { get; set; }
        
        /// <summary>
        /// 用户导航属性
        /// </summary>
        [ForeignKey(nameof(UserId))]
        public User? User { get; set; }
        
        /// <summary>
        /// 添加人导航属性
        /// </summary>
        [ForeignKey(nameof(AddedBy))]
        public User? AddedByUser { get; set; }
    }
}

    
